package cn.cookyfly.dailyreview.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class DailyReview implements EntryPoint {

  private static Workbench workbench;
  private static LoginPanel loginPanel;

/**
   * This is the entry point method.
   */
  public void onModuleLoad() {
	  RpcCaller.getCaller().checkLogin(new AsyncCallback<Boolean>() {
		public void onFailure(Throwable caught) {
			Window.alert("RPC calling failed.");
		}
		public void onSuccess(Boolean result) {
			if ((result != null) && (result.booleanValue()))
				showWorkbench();
			else
				showLogin();
		}
	  });
  }

  public static void showLogin() {
	  RootPanel rootPanel = RootPanel.get();
	  rootPanel.clear();
	  
	  if (loginPanel == null) loginPanel = new LoginPanel();
	  
	  rootPanel.add(loginPanel);
  }
  
  public static void showWorkbench() {
	  RootPanel rootPanel = RootPanel.get();
	  rootPanel.clear();
	  
	  if (workbench == null)
		  workbench = new Workbench();
	  
	  rootPanel.add(workbench);
  }
  
}
